package remote.collections
{
	public class ArrayCollection implements IList
	{
		private var _source:Array;
		public function ArrayCollection()
		{
			_source = new Array();
		}
		
		public function get length():int
		{
			return _source.length;
		}
		
		public function addItem(item:Object):void
		{
			_source.push(item)
		}
		
		public function addItemAt(item:Object, index:int):void
		{
			_source.splice(index, 0, item)
		}
		
		public function removeItem(item:Object):Object
		{
			var index:int = this.getItemIndex(item);
			if(index >= 0)
				return _source.splice(index, 1)[0];
			return null;
		}
		
		public function removeItemAt(index:int):Object
		{
			return _source.splice(index, 1)[0];
		}
		
		public function getItemAt(index:int):Object
		{
			return _source[index];
		}
		
		public function getItemIndex(item:Object):int
		{
			return _source.indexOf(item);
		}
		
		public function removeAll():void
		{
			_source.splice(0);
		}
		
		public function setItemAt(item:Object, index:int):Object
		{
			var oldIndex:int = this.getItemIndex(item);
			if(oldIndex != index)
			{
				this.addItemAt(removeItemAt(oldIndex), index);	
			}
			return item;
		}
		
		public function toArray():Array
		{
			return _source.concat();
		}

		public function get source():Array
		{
			return _source;
		}

		public function set source(value:Array):void
		{
			_source = value;
		}

		
	}
}